package logic

import (
	"context"
	"product/model/mysql"

	"product/goodsrpc/goodsrpc"
	"product/goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodsLogic {
	return &AddGoodsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddGoodsLogic) AddGoods(in *goodsrpc.AddGoodsRequest) (*goodsrpc.AddGoodsResponse, error) {
	// todo: add your logic here and delete this line

	good := mysql.Good{
		Name:   in.Name,
		Img:    in.Img,
		UserId: int(in.Userid),
	}
	mysql.DB.Create(&good)
	return &goodsrpc.AddGoodsResponse{Id: int64(good.ID)}, nil
}
